package com.zretc.controller;

import com.zretc.entity.HouseManager;
import com.zretc.service.HouseManagerService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/houseMangerLoginController")
public class HouseMangerLoginController {
    private static final Logger logger = LoggerFactory.getLogger(HouseMangerController.class);
    @Autowired
    private HouseManagerService houseManagerService;

    @RequestMapping("/login")
    public @ResponseBody boolean login(@RequestParam(value = "houseManagerName") String houseManagerName,
                                       @RequestParam(value = "houseManagerPsw") String houseManagerPsw,
                                       HttpSession session){

        logger.info("====登录用户名：" + houseManagerName);
        logger.info("====登录密码：" + houseManagerPsw);

        HouseManager houseManager = houseManagerService.login(houseManagerName, houseManagerPsw);

        if (houseManager == null){
            return false;
        }else{
            // 将用户信息存储session会话中
            session.setAttribute("houseManager",houseManager);
        }
        return true;
    }

    @RequestMapping("/logout")
    public @ResponseBody boolean logout(HttpSession session){

        // 清除session中指定属性
        session.removeAttribute("houseManager");
        return true;

    }

}
